package com.ruoyi.developer.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;


import com.ruoyi.developer.config.RuoYiConfig;
import com.ruoyi.file.utils.FileUploadUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.developer.domain.TDeveloper;
import com.ruoyi.developer.service.ITDeveloperService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;


/**
 * 开发商列表Controller
 * 
 * @author ruoyi
 * @date 2025-09-10
 */
@RestController
@RequestMapping("/developer")
public class TDeveloperController extends BaseController
{
    @Autowired
    private ITDeveloperService tDeveloperService;

    /**
     * 查询开发商列表列表
     */
    @RequiresPermissions("developer:developer:list")
    @GetMapping("/list")
    public TableDataInfo list(TDeveloper tDeveloper)
    {
        startPage();
        List<TDeveloper> list = tDeveloperService.selectTDeveloperList(tDeveloper);
        return getDataTable(list);
    }

    /**
     * 导出开发商列表列表
     */
    @RequiresPermissions("developer:developer:export")
    @Log(title = "开发商列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TDeveloper tDeveloper)
    {
        List<TDeveloper> list = tDeveloperService.selectTDeveloperList(tDeveloper);
        ExcelUtil<TDeveloper> util = new ExcelUtil<TDeveloper>(TDeveloper.class);
        util.exportExcel(response, list, "开发商列表数据");
    }

    /**
     * 获取开发商列表详细信息
     */
    @RequiresPermissions("developer:developer:query")
    @GetMapping(value = "/{developerId}")
    public AjaxResult getInfo(@PathVariable("developerId") Long developerId)
    {
        return success(tDeveloperService.selectTDeveloperByDeveloperId(developerId));
    }

    /**
     * 新增开发商列表
     */
    @RequiresPermissions("developer:developer:add")
    @Log(title = "开发商列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDeveloper tDeveloper)
    {
        return toAjax(tDeveloperService.insertTDeveloper(tDeveloper));
    }

    /**
     * 修改开发商列表
     */
    @RequiresPermissions("developer:developer:edit")
    @Log(title = "开发商列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDeveloper tDeveloper)
    {
        return toAjax(tDeveloperService.updateTDeveloper(tDeveloper));
    }

    /**
     * 删除开发商列表
     */
    @RequiresPermissions("developer:developer:remove")
    @Log(title = "开发商列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{developerIds}")
    public AjaxResult remove(@PathVariable Long[] developerIds)
    {
        return toAjax(tDeveloperService.deleteTDeveloperByDeveloperIds(developerIds));
    }


    @PostMapping("/upload")
    public AjaxResult uploadFile(MultipartFile file) throws Exception {
        try {
            // 上传文件路径
            String filePath = RuoYiConfig.getUploadPath();
            // 上传并返回结果

            FileUploadUtils.upload(filePath, file);
            // 返回成功信息
            return AjaxResult.success("上传成功");
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
    }
}
